package cn.edu.qvtu;

import java.util.Scanner;

public class test
{
    public static int gcd(int a, int b)//通过递归方法求出两个数的最大公约数
    {
        if (b == 0)//除数不能为0
        {
            return a;
        }
        else
        {
            return gcd(b, a % b);
        }
    }

    public static int gcd(int[] nums)
    {
        int result = 0;
        for (int i = 0; i < nums.length; i++)
        {
            result = gcd(result, nums[i]);//将相邻两个数的最大公约数赋值给result
        }
        return result;
    }

    public static void main(String[] args)
    {
        System.out.println("输入求几个数的最大公约数");
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int[] nums=new int[n];
        Scanner sc=new Scanner(System.in);
        for (int i = 0; i < nums.length; i++)
        {
            nums[i] = sc.nextInt();
        }
        System.out.println(gcd(nums));
    }
}
